package com.maikec.configure;
/**
 * 邢帅教育
 * <p>
 * 本源代码由数据中心及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2018. [图片]xsteach.com all rights reserved.
 */

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @description
 * @author maikec
 * @date 2018/7/9
 */
@Configuration
@ConfigurationProperties(prefix = "schedule")
//@EnableScheduling
//@EnableAsync
public class SchedulerConfig {
    private int corePoolSize;

    public int getCorePoolSize() {
        return corePoolSize;
    }

    public void setCorePoolSize(int corePoolSize) {
        this.corePoolSize = corePoolSize;
    }

    public int getQueueCapacity() {
        return queueCapacity;
    }

    public void setQueueCapacity(int queueCapacity) {
        this.queueCapacity = queueCapacity;
    }

    public int getMaxPoolSize() {
        return maxPoolSize;
    }

    public void setMaxPoolSize(int maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }

    private int maxPoolSize;
    private int queueCapacity;

    @Bean("taskExecutor")
    public TaskExecutor threadPoolTaskExecutor() {
        TaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        ((ThreadPoolTaskExecutor) taskExecutor).setCorePoolSize(this.getCorePoolSize());
        ((ThreadPoolTaskExecutor) taskExecutor).setMaxPoolSize(this.getMaxPoolSize());
        ((ThreadPoolTaskExecutor) taskExecutor).setQueueCapacity(this.getQueueCapacity());
        return taskExecutor;
    }
}
